﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;

namespace Moogle
{
    /// <summary>
    /// DbHelper class. This class extends the SqlLiteOpenHelper class for the purposes
    /// of this application. Specifically on initialization, it handles verifying the state/existence 
    /// of the moogle database. If the database file does not exist, then during initialization,
    /// this class will create it. 
    /// </summary>
    class DBHelper : Android.Database.Sqlite.SQLiteOpenHelper
    {
        private const string DbName = "moogle";
        private const int DbVersion = 1;

        public DBHelper(Context context)
            : base(context, DbName, null, DbVersion)
        {

        }

        #region OnCreate Control Function
        /// <summary>
        /// Class (or Activity) entry point.
        /// </summary>
        /// <param name="bundle">Android.OS.Bundle object instance that can be used to pass data to activity at startup.</param>
        public override void OnCreate(Android.Database.Sqlite.SQLiteDatabase db)
        {
            /// Create PrescribedMedication Table
            db.ExecSQL(@"CREATE TABLE IF NOT EXISTS PrescribedMedication (PrescribedMedicationID INTEGER PRIMARY KEY AUTOINCREMENT," +
                "Type varchar(30) NOT NULL, Name varchar(100) NOT NULL)");
            /// Create PopTime Table
            db.ExecSQL(@"CREATE TABLE IF NOT EXISTS PopTime (PopTimeID Integer PRIMARY KEY AUTOINCREMENT,MedicationName varchar(100) NOT NULL," +
                "Hour Integer NOT NULL,Minute Integer NOT NULL,AnteMeridiem bit NOT NULL,PostMeridiem bit NOT NULL)");

        }
        #endregion

        public override void OnUpgrade(Android.Database.Sqlite.SQLiteDatabase db, int oldVersion, int newVersion)
        {
            db.ExecSQL("DROP TABLE IF EXISTS PrescribedMedication");

            OnCreate(db);
        }


    }
}
